import {reqDetail,reqShopping} from '@/api/index'
import {UUID} from '@/utils/uuid_token'
export default {
    namespaced: true,
    actions:{
        getDetail(store,value){
            reqDetail(value).then(name=>{
                if(name.code === 200){
                store.commit('ABC',name.data)
            }
            })
        },
        async getShopping(store,value){
            let result = await reqShopping(value[0],value[1])
            if(result.code === 200){
                return result.ok
            }else{
                return Promise.reject(result.ok)
            }
        }
    },
    mutations:{
        ABC(state,value){
            state.goodsData = value
        }
    },
    state:{
        goodsData:{},
        uuidtoken:UUID()
    },
    getters:{
        road(state){
            // if(state.goodsData){
            //     return state.goodsData.categoryView //第一种写法
            // }else{
            //     return {}
            // }
            return state.goodsData.categoryView || {}
        },
        skuInfo(state){
            return state.goodsData.skuInfo || {}    //第二种写法
        },
        spuSaleAttrList(state){
            return state.goodsData.spuSaleAttrList || {}
        }
    }
}